import 'dart:ui';

import 'package:flutter/material.dart';

const String desString = '''
物品简介物品简介物品简介,物品简介物品简介物品简介,物品简介物品简介物品

介物品简介,物品简介物品简介,物品简介物品简介物品
简介物品简介物品简介物品简介物品简介,简介物品简介物品简介物品简介物品简介物品简介物品简介物品简介物品简介,物品简介物品简介物品简''';

class _TH {
  const _TH._();

  static double? _sw;
  static double? _sh;
  static double? _statusBarHeight;

  static double get _getSw {
    _sw ??= MediaQueryData.fromWindow(window).size.width;
    return _sw!;
  }

  static double get _getSh {
    _sh ??= MediaQueryData.fromWindow(window).size.height;
    return _sh!;
  }

  static double get _getStatusBarHeight {
    _statusBarHeight ??= MediaQueryData.fromWindow(window).padding.top;
    return _statusBarHeight!;
  }
}

/// 主题对象
ThemeData th(BuildContext context) => Theme.of(context);

/// 亮色主题
ThemeData get lightTheme => ThemeData(
      splashFactory: NoSplash.splashFactory,
      primaryColor: themeColor,
      cardColor: Colors.blueGrey,
      primarySwatch: themeSwatch,
      errorColor: Colors.red[300],
      textTheme: const TextTheme(
        bodyText1: TextStyle(color: Colors.black),
      ),
    );

/// 原始主题色
Color get themeColor => const Color(0xff0c88ea);

/// 主题
MaterialColor get themeSwatch => Colors.blue;

/// 主题色
Color theme(BuildContext context) => th(context).primaryColor;

/// 第二主题色
Color theme2(BuildContext context) => th(context).hoverColor;

/// 白色(来自底部导航栏颜色)
Color white(BuildContext context) => th(context).bottomAppBarColor;

/// 黑色(来自标题)
Color black(BuildContext context) => th(context).textTheme.bodyText1!.color!;

/// 禁用颜色
Color disable(BuildContext context) => th(context).disabledColor;

/// canvas颜色
Color canvas(BuildContext context) => th(context).canvasColor;

/// 警告色
Color red(BuildContext context) => th(context).errorColor;

/// 屏幕宽度
double get sw => _TH._getSw;

/// 屏幕高度
double get sh => _TH._getSh;

/// 状态栏高度
double get statusBarHeight => _TH._getStatusBarHeight;

/// 颜色扩展
extension ExColor on Color {
  /// 暗一点
  Color darken([double amount = .1]) {
    assert(amount >= 0 && amount <= 1);

    final HSLColor hsl = HSLColor.fromColor(this);
    final HSLColor hslDark = hsl.withLightness((hsl.lightness - amount).clamp(0.0, 1.0));

    return hslDark.toColor();
  }

  /// 亮一点
  Color lighten([double amount = .1]) {
    assert(amount >= 0 && amount <= 1);

    final HSLColor hsl = HSLColor.fromColor(this);
    final HSLColor hslLight = hsl.withLightness((hsl.lightness + amount).clamp(0.0, 1.0));

    return hslLight.toColor();
  }
}
